package com.example.迭代器模式;

import java.util.Iterator;

/**
 * 晚餐菜单遍历类
 */
public class DinnerMenuIterator implements Iterator {
    Menu[] menuItems;
    int position = 0;

    public DinnerMenuIterator(Menu[] menuItems) {
        this.menuItems = menuItems;
    }

    @Override
    public boolean hasNext() {
        if (position >= menuItems.length || menuItems[position] == null) {
            return false;
        }

        return true;
    }

    @Override
    public Object next() {
        Menu menuItem = menuItems[position];
        position++;
        return menuItem;
    }
}
